import 'package:flutter/material.dart';
import 'package:flutter_demo/widgets/textWidget.dart';
import 'package:flutter_demo/widgets/groupSlotWidget.dart';

import 'package:flutter_demo/models/meItem.dart';

class MUnLogin extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(20.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              MText(
                "未登录",
                fontSize: 18.0,
                isBold: true,
              ),
              SizedBox(height: 8.0),
              MText(
                "点击登录商店",
                fontSize: 14.0,
                color: Colors.grey,
              ),
            ],
          ),
          Icon(
            Icons.account_circle,
            size: 80.0,
            color: Colors.grey[500],
          ),
        ],
      ),
    );
  }
}

class MMeHeader extends StatelessWidget {
  final String title;
  final String detail;
  final bool showDivider;
  final Widget _header;

  MMeHeader(
    this.title, {
    this.detail,
    this.showDivider = true,
  })  : assert(title != null),
        _header = Padding(
          padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 15.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              MText(title, fontSize: 16.0),
              MText(detail, color: Colors.grey),
            ],
          ),
        );

  @override
  Widget build(BuildContext context) {
    return showDivider
        ? Column(
            children: <Widget>[
              Container(
                color: Colors.grey[200],
                height: 8.0,
              ),
              _header,
            ],
          )
        : _header;
  }
}

class MeLineWidget extends StatelessWidget {
  const MeLineWidget({
    Key key,
    @required this.items,
  }) : super(key: key);

  final List<MMeItem> items;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Container(
          height: 1.0,
          color: Colors.grey[300],
        ),
        SizedBox(height: 15.0),
        Row(
          children: items.map((MMeItem item) {
            return Expanded(
              child: FlatButton(
                onPressed: item.title == "" ? null : () {},
                child: Column(
                  children: <Widget>[
                    Icon(item.icon),
                    MText(
                      item.title,
                      fontSize: 11.0,
                    ),
                  ],
                ),
              ),
            );
          }).toList(),
        ),
        SizedBox(height: 15.0),
      ],
    );
  }
}

//我的订单
class MOrder extends StatelessWidget {
  final List<MMeItem> items;
  MOrder(this.items) : assert(items != null);

  @override
  Widget build(BuildContext context) {
    return MGroupSlot(
      padding: 20.0,
      header: MMeHeader(
        "我的订单",
        detail: "查看全部订单",
      ),
      body: new MeLineWidget(items: items),
    );
  }
}

//三单好礼
class MGift extends StatelessWidget {
  List<String> steps = ["第1单", "第2单", "第3单"];

  @override
  Widget build(BuildContext context) {
    return MGroupSlot(
      padding: 20.0,
      header: MMeHeader(
        "三单好礼",
        detail: "查看详情",
      ),
      body: Padding(
        padding: const EdgeInsets.symmetric(vertical: 15.0),
        child: Stack(
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(top: 12.0, left: 55.0, right: 55.0),
              color: Colors.grey[300],
              height: 1.0,
            ),
            Row(
              children: steps.map((String item) {
                return Expanded(
                  child: FlatButton(
                    onPressed: () {},
                    child: Column(
                      children: <Widget>[
                        Icon(
                          Icons.play_circle_filled,
                          color: Colors.grey,
                        ),
                        MText(
                          item,
                          fontSize: 10.0,
                          color: Colors.grey,
                        ),
                      ],
                    ),
                  ),
                );
              }).toList(),
            ),
          ],
        ),
      ),
    );
  }
}

//我的服务
class MServer extends StatelessWidget {
  final List<List<MMeItem>> items;
  MServer(this.items) : assert(items != null);

  @override
  Widget build(BuildContext context) {
    return MGroupSlot(
      padding: 20.0,
      header: MMeHeader(
        "我的服务",
        detail: "",
      ),
      body: Column(
        children: items.map((List<MMeItem> item) {
          return MeLineWidget(items: item);
        }).toList(),
      ),
    );
  }
}
